
package de.unihannover.se.restlab.microblog.jpamodels;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import de.unihannover.se.restlab.microblog.models.Role;

@Entity
@Table(name="MyAccounts")
@NamedQueries({
	@NamedQuery(name="Account.findAll", query="select a from Account a")
})
public class Account {

	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Id
	private int accountId;

	@OneToOne
	private User user;

	private Role role;

	private String password;

	//private Link self;

	public Account (User u, Role r, String p) {
		user = u;
		role = r;
		password = p;
		//accountId = idCounter++;
	}

	public Account (User u, Role r) {
		this(u, r, "0000");
	}

	public Account () {
// this(null, Role.User, "0000");
	}

	public Account (de.unihannover.se.restlab.microblog.models.Account acc) {
		accountId = acc.getAccountId();
		user = new User(acc.getUser());
		role = acc.getRole();
		password = acc.getPassword();
	}

	public User getUser () {
		return user;
	}

	public void setUser (User user) {
		this.user = user;
	}

	public Role getRole () {
		return role;
	}

	public void setRole (Role role) {
		this.role = role;
	}

	public String getPassword () {
		return password;
	}

	public void setPassword (String password) {
		this.password = password;
	}

	public int getAccountId () {
		return accountId;
	}

	/*public Link getSelf () {
		return self;
	}

	public void setSelf (Link self) {
		this.self = self;
	}*/

	public void setAccountId (int accountId) {
		this.accountId = accountId;
	}

	@Override
	public String toString () {
		return "Account [accountId=" + accountId + ", user=" + user + ", role=" + role + "]";
	}

}
